<?php
/**
 * 这是判断用户浏览器的类
 * User: ford
 * Date: 15-6-13
 * Time: 下午3:30
 */

class MobileSniffer {
	private $userAgent;
	private $device;
	private $browser;
	private $deviceLength;
	private $browserLength;

	public function __construct() {
		$this->userAgent = $_SERVER['HTTP_USER_AGENT'];
		$this->userAgent = strtolower($this->userAgent);

		$this->device = array('iphone', 'ipad', 'android', 'silk', 'blackberry', 'touch', 'linux');
		$this->browser = array('firefox', 'chrome', 'opera', 'msie', 'safari', 'blackberry', 'trident');
		$this->deviceLength = count($this->device);
		$this->browserLength = count($this->browser);

	}

	public function findDevice() {
		for($uaSniff = 0; $uaSniff < $this->deviceLength; $uaSniff++) {
			if(strstr($this->userAgent, $this->device[$uaSniff])) {
				return $this->device[$uaSniff];
			}
		}
	}

	public function findBrowser() {
		for($uaSniff = 0; $uaSniff < $this->browserLength; $uaSniff++) {
			if(strstr($this->userAgent, $this->browser[$uaSniff])) {
				return $this->browser[$uaSniff];
			}
		}
	}

}